<?php
/**
 * Phpwell Web Client Basic Unit Test
 */

/**
 * Imports
 */
$phpwell_dir = dirname(dirname(dirname(__FILE__)));
require_once(sprintf('%s/%s', $phpwell_dir, 'import.php'));
import_well('vendor/simpletest/unit_tester');
import_well('web/client');


/**
 * Test Class
 */
class HttpClientUnitTestCase extends UnitTestCase {

    var $has_started_all = 0;
    var $started_at = 0;
    var $script_time = 0;
    var $Browser = NULL;

    /**
     * Meta Methods
     */
    function setUp() {
        $this->startAll();
        $this->Browser = new HttpClient();
        $this->Browser->error_on_unexpected_code = 0;
    }

    function tearDown() {
        $this->Browser = NULL;
        $this->endAll();
    }

    function startAll() {
        if ( $this->has_started_all ) {
            return;
        }

        $this->started_at = microtime(1);
        $this->has_started_all = 1;
    }

    function endAll() {
        $this->script_time = number_format(microtime(1) - $this->started_at, 4);
    }

    /**
     * Test Methods
     */
    function testInstance() {
        $this->assertTrue(is_a($this->Browser, 'HttpClient'));
    }

    function testGetQueryString() {
        $url = 'http://localhost/';
        $ParamDict = array( 'foo' => 'bar' );
        $query_url = $this->Browser->add_url_query_string($url, $ParamDict);
        $expect = 'http://localhost/?foo=bar';
        $this->assertEqual($query_url, $expect);
    }
}

$Test = &new HttpClientUnitTestCase();
$Test->run(new HtmlReporter());
printf('<h6 id="script_time">completed in %s s</h6>', $Test->script_time);
